package com.t2t.top.rocketmq.spring;

import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import com.alibaba.rocketmq.common.message.MessageExt;

import java.util.List;

/**
 * 监听wrapper，用于处理共通业务，并转发消息到业务监听中.
 * <p/>
 * Created by yangpengfei on 2015/11/3.
 */
public class ExampleMessageWrapper implements MessageListenerConcurrently {

    private ExampleMessageListener exampleMessageListener;

    public ExampleMessageListener getExampleMessageListener() {
        return exampleMessageListener;
    }

    public void setExampleMessageListener(ExampleMessageListener exampleMessageListener) {
        this.exampleMessageListener = exampleMessageListener;
    }

    //SimpleExampleMessageListener的处理是否返回成功，不成功则重新接收
    public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
        //实现共通的业务
        if (exampleMessageListener.onMessage(list, consumeConcurrentlyContext)) {
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
        return ConsumeConcurrentlyStatus.RECONSUME_LATER;

    }
}
